package com.kaifamiao.month05.day15;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

public class SortStudent {

    public static void main(String[] args) {
        StudentEntity stu1 = new StudentEntity("张三", "男",54);
        StudentEntity stu2 = new StudentEntity("王五", "女",45);
        StudentEntity stu3 = new StudentEntity("孙六", "女",51);
        StudentEntity stu4 = new StudentEntity("李四", "男",65);
        StudentEntity stu5 = new StudentEntity("赵七", "男",70);

        TreeSet<StudentEntity> set = new TreeSet<>(
                (o1, o2) -> (int)(o2.getWeight() - o1.getWeight())
        );

        set.add(stu1);
        set.add(stu2);
        set.add(stu3);
        set.add(stu4);
        set.add(stu5);
        List<StudentEntity> list = new ArrayList<>(set);
        for (StudentEntity s : list) {
            System.out.println(s);
        }
    }

}
@Data
class StudentEntity {

    private String name;
    private String gender;
    private double weight;

    public StudentEntity(String name, String gender, double weight) {
        this.name = name;
        this.gender = gender;
        this.weight = weight;
    }
}
